<?php
$model = new BDynamicFormModel();
$parentRoleField = 'media_parentRoleId_admin_role';
$model->addField($parentRoleField);
$adminRoleData = array();
$memberRoleData = array();
$customerRoleData = array();
if (isset($spaceRoleData)) {
    if (isset($spaceRoleData['adminRoleData']))
        $adminRoleData = $spaceRoleData['adminRoleData'];
    if (isset($spaceRoleData['memberRoleData']))
        $memberRoleData = $spaceRoleData['memberRoleData'];
    if (isset($spaceRoleData['customerRoleData']))
        $customerRoleData = $spaceRoleData['customerRoleData'];
}
?>
<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "manage-myInfo-form",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('class' => 'form-signin', 'role' => 'form'),
        ));
?>
<div class=" pull-right">
    <?php echo $control->getAjaxLink(array('name' => '机构成员列表', 'id' => 'showMemberList')); ?>|管理机构角色|
    <?php echo $control->getAjaxLink(array('name' => '管理申请规则', 'id' => BUIMembership::Show_Admin_Membership)); ?>
</div>
<br>
<?php if (isset($addRoleResult)) { ?>
    <?php
    if ($addRoleResult == 'success') {
        echo '<p class="bg-success">add child role successfully!</p>';
    } else {
        echo '<p class="bg-danger">add child role fail!</p>';
    }
    ?>
<?php } ?>

<legend><h5>机构的所有客户角色</h5></legend>
<table class="table table-striped">
    <thead>
        <tr>
            <th>应用名</th>
            <th>角色全名</th>
            <th>别名</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($customerRoleData as $role) {
            $roleName = $role->getName();
            if ($roleName == 'all_roles')
                continue;
            $roleFullName = $role->getFullName();
            $alias = BUIRole::getRoleAliasByFullName($roleFullName);
            if(!$alias){
                $alias = $roleName;
            }
            $appId = $role->appId;
            $appClass = 'BApp';
            if ($appId > 0) {
                $app = bapp::getAppById($appId);
                $appClass = get_class($app);
            }
            $roleFullName = str_replace('app_root.app_customer.', '\\\\',$roleFullName );
            ?>
            <tr>
                <td><?php echo $appClass; ?></td>
                <td><?php echo $roleFullName; ?></td>
                <td><?php echo $alias; ?></td>
                <td><?php
                    echo $control->getAjaxLink(array(
                        'name' => '添加子角色', 'id' => BUIRole::Show_Add_Role), array(
                        'roleId' => $role->getId()));
                    ?>|
                    <?php
                    echo $control->getAjaxLink(array(
                        'name' => '删除', 'id' => BUIRole::Delete_Child_Role), array(
                        'roleId' => $role->getId()));
                    ?>
                </td>
            </tr>
        <?php } ?>
    </tbody>
</table>

<legend><h5>机构的所有成员角色</h5></legend>
<table class="table table-striped">
    <tbody>
        <?php
        foreach ($memberRoleData as $role) {
            $roleName = $role->getName();
            if ($roleName == 'all_roles')
                continue;
            $roleFullName = $role->getFullName();
            $alias = BUIRole::getRoleAliasByFullName($roleFullName);
            if(!$alias){
                $alias = $roleName;
            }
            $appId = $role->appId;
            $appClass = 'BApp';
            if ($appId > 0) {
                $app = bapp::getAppById($appId);
                $appClass = get_class($app);
            }
            $roleFullName = str_replace('app_root.app_member.', '\\\\',$roleFullName );
            ?>
            <tr>
                <td><?php echo $appClass; ?></td>
                <td><?php echo $roleFullName; ?></td>
                <td><?php echo $alias; ?></td>
                <td><?php
                    echo $control->getAjaxLink(array(
                        'name' => '添加子角色', 'id' => BUIRole::Show_Add_Role), array(
                        'roleId' => $role->getId()));
                    ?>|
                    <?php
                    echo $control->getAjaxLink(array(
                        'name' => '删除', 'id' => BUIRole::Delete_Child_Role), array(
                        'roleId' => $role->getId()));
                    ?>
                </td>
            </tr>
        <?php } ?>
    </tbody>
</table>

<legend><h5>机构的所有系统员角色</h5></legend>
<table class="table table-striped">
    <tbody>
        <?php
        foreach ($adminRoleData as $role) {
            $roleName = $role->getName();
            if ($roleName == 'all_roles')
                continue;
            $roleFullName = $role->getFullName();
            $alias = BUIRole::getRoleAliasByFullName($roleFullName);
            if(!$alias){
                $alias = $roleName;
            }
            $appId = $role->appId;
            $appClass = 'BApp';
            if ($appId > 0) {
                $app = bapp::getAppById($appId);
                $appClass = get_class($app);
            }
            $roleFullName = str_replace('app_root.app_admin.', '\\\\',$roleFullName );
            ?>
            <tr>
                <td><?php echo $appClass; ?></td>
                <td><?php echo $roleFullName; ?></td>
                <td><?php echo $alias; ?></td>
                <td>
                    <?php
                    echo $control->getAjaxLink(array(
                        'name' => '添加子角色', 'id' => BUIRole::Show_Add_Role), array(
                        'roleId' => $role->getId()));
                    ?>|
                    <?php
                    echo $control->getAjaxLink(array(
                        'name' => '删除', 'id' => BUIRole::Delete_Child_Role), array(
                        'roleId' => $role->getId()));
                    ?>
                </td>
            </tr>
        <?php } ?>
    </tbody>
</table>


<?php $this->endWidget(); ?>